package org.wevil.util.page;

import java.util.ArrayList;
import java.util.List;

/**
 * 分页返回数据集工具类
 *
 * @author wanglei
 * @since 2020/2/3
 */
public class PageResultUtil {
    /**
     * 要封装的数据集
     *
     * @param list     返回数据
     * @param current  当页页数
     * @param size 每页显示多少条
     * @param total    数据总数
     * @author wanglei
     * @since 2020/2/3
     */
    public static <T> PageResult<T> generateResult(List<T> list, int current, int size, long total) {
        Page page = new Page();
        page.setCurrent(current);
        page.setSize(size);
        page.setTotal(total);
        PageResult<T> reactResult = new PageResult<>();
        if (list!=null && list.size()>0) {
            reactResult.setList(list);
        } else {
            reactResult.setList(new ArrayList<>());
        }
        reactResult.setPage(page);
        return reactResult;
    }
}
